<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('AdminCategory/index')}">分类管理</a></li>
        <li class="active"><a href="{:url('AdminCategory/add')}">添加分类</a></li>
    </ul>
    <div class="row margin-top-20">
        <div class="col-md-2">
            <div class="list-group">
                <a class="list-group-item" href="#A" data-toggle="tab">基本属性</a>
                <a class="list-group-item" href="#B" data-toggle="tab">SEO设置</a>
                <a class="list-group-item" href="#C" data-toggle="tab">模板设置</a>
            </div>
        </div>
        <div class="col-md-4">
            <form class="layui-form js-ajax-form" method="post" lay-filter="variable">
                <div class="tab-content">
                    <div class="tab-pane active" id="A">
                        <div class="form-group">
                            <label for="input-parent"><span class="form-required">*</span>上级</label>
                            <div>
                                <select class="form-control" name="parent_id" id="input-parent">
                                    <option value="0">作为一级分类</option>
                                    {$categories_tree}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-name"><span class="form-required">*</span>分类名称</label>
                            <div>
                                <input type="text" class="form-control" lay-verify="required" id="input-name" name="name">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="input-parent"><span class="form-required">*</span>内容模型</label>
                            <div class="layui-form">
                                <select class="form-control layui-form-select" id="temp_ip" name="temp_ip" lay-filter="test">
                                    <volist name="arctype" id="v">
                                        <option value="{$v.id}">{$v.title}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="input-name">分类别名</label>
                            <div>
                                <input type="text" class="form-control" lay-verify="required" id="input-alias" name="alias">
                            </div>
                        </div>
                        <style type="text/css">
                            .layui-form-checkbox i{height: 30px;}
                        </style>
                        <div class="form-group layui-form-item">
                            <label for="input-parent">隐藏栏目</label>
                            <div>
                                <input type="checkbox" name="status" title="开启">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-description">描述</label>
                            <div>
                                <textarea class="form-control" name="description" id="input-description"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-description">缩略图</label>
                            <div>
                                <input type="hidden" name="thumbnail" class="form-control"
                                       id="js-thumbnail-input">
                                <div>
                                    <a href="javascript:uploadOneImage('图片上传','#js-thumbnail-input');">
                                        <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                             id="js-thumbnail-input-preview"
                                             width="135" style="cursor: pointer"/>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="B">
                        <div class="form-group">
                            <label for="input-seo_title">SEO标题</label>
                            <div>
                                <input type="text" class="form-control" id="input-seo_title" name="seo_title">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-seo_keywords">SEO关键字</label>
                            <div>
                                <input type="text" class="form-control" id="input-seo_keywords" name="seo_keywords">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-seo_description">SEO描述</label>
                            <div>
                                <textarea class="form-control" name="seo_description"
                                          id="input-seo_description"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="C">
                        <div class="form-group list_article">
                            <label for="input-list_tpl"><span class="form-required">*</span>列表模板</label>
                            <div>
                                <select class="form-control" name="list_tpl" id="input-list_tpl">
                                    <option value="list_article">portal/list_article.html</option>
                                </select>
                                <a href="javascript:;">添加模板</a>
                            </div>
                        </div>
                        <div class="form-group view_article">
                            <label for="input-one_tpl"><span class="form-required">*</span>文档模板</label>
                            <div>
                                <select class="form-control" name="one_tpl" id="input-one_tpl">
                                    <option value="view_article">portal/view_article.html</option>
                                </select>
                                <a href="javascript:;">添加模板</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <button type="button" class="btn btn-primary js-ajax-submit" lay-submit lay-filter="consub">{:lang('ADD')}</button>
                    <a class="btn btn-default" href="{:url('AdminCategory/index')}">{:lang('BACK')}</a>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    //根据内容模型赛选模板
    var url = "{:url('AdminCategory/ajax_select_temp')}";
    layui.use(['form'], function(){
        var form = layui.form;
        form.on('select(test)', function (data) {
            TempList(data.value,form);
        });
    });
    
    $(function () {
        layui.use(['form'], function(){
            var form = layui.form
            TempList($('#temp_ip option:first').val(),form);
        })
    })

    function TempList(tempnamem,form) {
        $('#input-list_tpl').empty();
        $('#input-one_tpl').empty();
        $.post(url,{id:tempnamem},function(result){
            if (result.data.list != undefined) {
                for(var i=0;i<result.data.list.length;i++){
                   $('#input-list_tpl').append(new Option(result.data.list[i]+'.html', result.data.list[i]));
                }
                var listname = "/portal/admin_category/add_theme/theme/"+result.data.listname+".html";
                $('.list_article div a').attr("href","javascript:parent.openIframeLayer('"+listname+"','添加模板',{});");
                $('.list_article').show();

            }else{
                $('.list_article').hide();
            }
            
            if (result.data.view != undefined){
                for(var i=0;i<result.data.view.length;i++){
                   $('#input-one_tpl').append(new Option(result.data.view[i]+'.html', result.data.view[i]));
                }
                var viewname = "/portal/admin_category/add_theme/theme/"+result.data.viewname+".html";
                $('.view_article div a').attr("href","javascript:parent.openIframeLayer('"+viewname+"','添加模板',{});")
                $('.view_article').show();
            }else{
                $('.view_article').hide();
            }
            form.render('select');
        },"json");

    }
    

    var addurl = "{:url('AdminCategory/addPost')}";
    layui.use(['form'], function(){
        LayuiPost(addurl);
    });
</script>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>


</body>
</html>